package com.yuanfeng.business.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.business.dto.ShopBaseListDTO;
import com.yuanfeng.business.entity.ShopCompany;
import com.yuanfeng.business.mapper.ShopCompanyMapper;
import com.yuanfeng.business.service.ShopCompanyService;
import com.yuanfeng.business.vo.ShopReturnBondListVO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.DateUtils;
import com.yuanfeng.commoms.util.ParseMapUtils;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.util.querypage.PageUtils;
import com.yuanfeng.commoms.util.querypage.Query;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 *
 */
@Service
public class ShopCompanyServiceImpl extends ServiceImpl<ShopCompanyMapper, ShopCompany>
    implements ShopCompanyService{

    @Override
    public ResponseResult updateShopReturnBond(ShopBaseListDTO param) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(param.getToken());
        if (null != userInfo) {
            //审核时间
            param.setUpdateTime(new Date());
            //操作人
            param.setShopOperator(userInfo.getUserRealname());
            //操作时间
            param.setShopOperatorTime(DateUtils.getNowDateToString());
            this.baseMapper.updateShopReturnBond(param);
            return ResponseResult.success();
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult queryShopReturnBondList(ShopBaseListDTO param) {
        try {
            //将对象转换为map
            Map data = ParseMapUtils.beanToMap(param);
            //分页查询数据
            IPage<ShopReturnBondListVO> page = this.baseMapper.queryShopReturnBondList(new Query<ShopReturnBondListVO>().getPage(data), param);
            return ResponseResult.success(PageUtils.getPage(page));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }
    }

    @Override
    public ResponseResult updateShopDeposit(ShopBaseListDTO param) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(param.getToken());
        if (null != userInfo) {
            //审核时间
            param.setUpdateTime(new Date());
            //操作人
            param.setShopOperator(userInfo.getUserRealname());
            //操作时间
            param.setShopOperatorTime(DateUtils.getNowDateToString());
            this.baseMapper.updateDeposit(param);
            return ResponseResult.success();
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult queryShopDepositList(ShopBaseListDTO param) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(param.getToken());
        if (null != userInfo) {
            try {
                //将对象转换为map
                Map data = ParseMapUtils.beanToMap(param);
                //分页查询数据
                IPage<ShopReturnBondListVO> page = this.baseMapper.queryBrandList(new Query<ShopReturnBondListVO>().getPage(data), param);

                return ResponseResult.success(PageUtils.getPage(page));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult delShopInfo(Map<String,String> map) {
        this.baseMapper.deleteShopBase(map.get("shopId"));
        //this.baseMapper.deleteShopCompany(map.get("shopId"));
        this.baseMapper.deleteShopJoinBase(map.get("userId"));
        this.baseMapper.deleteShopJoinPay(map.get("userId"));
        return ResponseResult.success();
    }
}




